package top.ywlog.permission.common;


import top.ywlog.permission.model.SysUser;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Durian
 */
@SuppressWarnings("unused")
public class RequestHolder
{

    /** 用户对象持有 */
    private static final ThreadLocal<SysUser> USER_HOLDER = new ThreadLocal<>();
    /** 请求对象持有 */
    private static final ThreadLocal<HttpServletRequest> REQUEST_HOLDER = new ThreadLocal<>();

    public static void add(SysUser sysUser)
    {
        USER_HOLDER.set(sysUser);
    }

    public static void add(HttpServletRequest request)
    {
        REQUEST_HOLDER.set(request);
    }

    public static SysUser getCurrentUser()
    {
        return USER_HOLDER.get();
    }

    public static HttpServletRequest getCurrentRequest()
    {
        return REQUEST_HOLDER.get();
    }

    public static void remove()
    {
        USER_HOLDER.remove();
        REQUEST_HOLDER.remove();
    }
}
